Index: C:/web/home/arcade.com/www/include/helpers.php
===================================================================
--- C:/web/home/arcade.com/www/include/helpers.php	(revision 82)
+++ C:/web/home/arcade.com/www/include/helpers.php	(revision 91)
@@ -167,7 +167,7 @@
 	$fCron = fopen( "include/cron.php", "w" );
 	if( $fCron )
 	{
-		fwrite( $fCron, "<?php \$cLastRun = ".Today()."; ?>" );
+		fwrite( $fCron, '<?php $cLastRun = ' . Today() . '; ?' . '>' );
 		$query = "INSERT INTO ".$GLOBALS["cMain"]["dbPrefix"]."stats SET date=".(Today()-1).", plays=$nPlays".", new_users=$nJoined";
 		$db->query( $query, false );
 	}
@@ -193,4 +193,36 @@
 	exit();
 }

+//----------------------------------------------------------
+// Recursively Remove directories
+//----------------------------------------------------------
+function delete($path = null)
+{
+	if( substr($path, -1) != '/' )
+	   $path .= '/';
+	if (is_dir($path) === true)
+	{
+		$files = glob($path . "*");
+		if (is_array($files))
+		{
+			foreach ($files as $file)
+			{
+				if (preg_match("/(\.|\.\.)$/", $file))
+					continue;
+				if (is_file($file) === true)
+					@unlink($file);
+				elseif (is_dir($file) === true)
+				{
+					if( delete($file) === false )
+						return false;
+     			}
+			}
+		}
+		$path = substr($path, 0, strlen($path) - 1);
+		if (rmdir($path) === false)
+			return false;
+	}
+	return true;
+}
+
 ?>
\ No newline at end of file
Index: C:/web/home/arcade.com/www/include/config.php
===================================================================
--- C:/web/home/arcade.com/www/include/config.php	(revision 82)
+++ C:/web/home/arcade.com/www/include/config.php	(revision 91)
@@ -1,6 +1,6 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.3.2
+/ ProArcadeScript version: 1.4
 / File description:
 / main configuration file for ProArcadeScript. It can't be changed
 / using admin control panel.
@@ -16,7 +16,7 @@
 require_once( "pages_config.php" );
 require_once( 'usersettings.php' );

-$version = '1.3.2';
+$version = '1.4';

 // strings for DB queries. Please do not edit
 $cSort = array(
Index: C:/web/home/arcade.com/www/include/sitesettings.php
===================================================================
--- C:/web/home/arcade.com/www/include/sitesettings.php	(revision 82)
+++ C:/web/home/arcade.com/www/include/sitesettings.php	(revision 91)
@@ -1,10 +1,10 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.1
+/ ProArcadeScript version: 1.4
 / File description:
 / Site configuration. Edit it manually or using admin's control panel
 /
-/  2007, ProArcadeScript. All rights reserved.
+/  2007-2009, ProArcadeScript. All rights reserved.
 /*******************************************************************/

 $cSite = array(
@@ -13,12 +13,14 @@
 	"sSiteRoot"		=>	"/",	// if the script will be installed in a folder, the root must be "/folder/"
 	"sURL"			=>	"http://www.arcade.com",
 	"sSiteTitle"	=>	"Arcadeous",
-	"sCopyright"	=>	"© 2006 ProArcadeScript.com",
+	"sCopyright"	=>	"© 2009 ProArcadeScript.com",
 	"sSiteDesc"		=>	"This is a sample site for the script",
 	"sSiteKeywords"	=>	"Flash, Arcade, Games, Free, Online",
-	"sTemplate"		=>	"Oldschool",
+	"sTemplate"		=>	"Toys",
 	"bSeo"			=>	true,		// search engine friendly links
-
+	"bCache"       => false,
+	"cacheTTL"     => 3200,
+
 //  Site Admin information
 	"sAdminName"		=>	"Serggg",
 	"sAdminEmail"		=>	"admin@oldschoolarcades.com",
Index: C:/web/home/arcade.com/www/include/class.Cache.php
===================================================================
--- C:/web/home/arcade.com/www/include/class.Cache.php	(revision 0)
+++ C:/web/home/arcade.com/www/include/class.Cache.php	(revision 91)
@@ -0,0 +1,185 @@
+<?php
+/*******************************************************************
+/ ProArcadeScript version: 1.4
+/ File description:
+/ Implementation of the CCache class
+/
+/  2007-2009, ProArcadeScript.com. All rights reserved.
+/*******************************************************************/
+
+
+//-----------------------------------------------------------------------------------------
+// helper function which recursively removes a directory
+//
+// to use this function to totally remove a directory, write:
+// remove_directory('path/to/directory/to/delete');
+// to use this function to empty a directory, write:
+// remove_directory('path/to/full_directory',TRUE);
+//-----------------------------------------------------------------------------------------
+function remove_directory( $directory, $empty=FALSE )
+{
+	if(substr($directory,-1) == '/')
+		$directory = substr($directory,0,-1);
+	if(!file_exists($directory) || !is_dir($directory))
+		return FALSE;
+	elseif(is_readable($directory))
+	{
+		$handle = opendir($directory);
+		while (FALSE !== ($item = readdir($handle)))
+		{
+			if($item != '.' && $item != '..')
+			{
+				$path = $directory.'/'.$item;
+				if(is_dir($path))
+					remove_directory($path);
+				else
+					unlink($path);
+			}
+		}
+		closedir($handle);
+		if($empty == FALSE)
+			if(!rmdir($directory))
+				return FALSE;
+	}
+	return TRUE;
+}
+
+
+
+
+
+//-----------------------------------------------------------------------------------------
+// Class CCache
+//-----------------------------------------------------------------------------------------
+class CCache
+{
+	var $ttl = 2000; // Time to leave, seconds
+	var $cache_root = '';
+	var $enabled = false;
+
+//-----------------------------------------------------------------------------------------
+function CCache()
+{
+	$path = $_SERVER['DOCUMENT_ROOT'] . $GLOBALS['cSite']['sSiteRoot'] . 'cache';
+	$this->ttl = $GLOBALS['cSite']['cacheTTL'];
+	if( !is_dir($path) )
+	{
+		mkdir( $path, 0775 );
+		$file = fopen( $path . '/index.html', 'w' );
+		if( $file )
+		{
+			fwrite( $file, ' ' );
+			fclose( $file );
+		}
+	}
+	$this->cache_root = "$path/";
+	$this->enabled = $GLOBALS["cSite"]["bCache"];
+}
+
+//-----------------------------------------------------------------------------------------
+function get()
+{
+	if( !$this->enabled )
+	   return false;
+
+	$name = $_SERVER['REQUEST_URI'];
+	$ext =  $_SESSION['user'];
+	$hash = sha1($name);
+	$hash_ext = sha1($ext);
+	$cache_dir = substr( $hash, 0, 5 );
+	$cache_subdir = substr( $hash, 5, 5 );
+	$time = date( 'U' );
+	$cache_file = $this->cache_root . $cache_dir . '/' . $cache_subdir . '/' . $hash . '.' . $hash_ext;
+	if( file_exists($cache_file) && ($time - filemtime($cache_file) < $this->ttl) )
+	{
+		$file = fopen( $cache_file, 'r' );
+		if( $file )
+		{
+			$data = fread( $file, filesize($cache_file) );
+			fclose( $file );
+			return unserialize( $data );
+		}
+		else
+			return false;
+	}
+	else
+	   return false;
+
+}
+
+//-----------------------------------------------------------------------------------------
+function write( $data )
+{
+	if( !$this->enabled )
+	   return true;
+
+	$name = $_SERVER['REQUEST_URI'];
+	$ext =  $_SESSION['user'];
+	$hash = sha1($name);
+	$hash_ext = sha1($ext);
+	$cache_dir = $this->cache_root . '/' . substr( $hash, 0, 5 );
+	$cache_subdir = $cache_dir . '/' . substr( $hash, 5, 5 );
+	if( !is_dir($cache_dir) )
+		mkdir( $cache_dir, 0775 );
+	if( !is_dir($cache_subdir) )
+		mkdir( $cache_subdir, 0775 );
+	$file = fopen( $cache_subdir.'/'.$hash.'.'.$hash_ext, 'w' );
+	if( $file )
+	{
+		$res = fwrite( $file, serialize($data) );
+		fclose( $file );
+		return $res;
+	}
+	return false;
+}
+
+//-----------------------------------------------------------------------------------------
+function delete( $what, $id, $title )
+{
+	switch( $what )
+	{
+	   case 'game':
+	      $name = GameURL( $id, $title );
+			$hash = sha1($name);
+   		$cache_dir = (substr($this->cache_root,-1) == '/') ? substr( $this->cache_root, 0, -1 ) : $this->cache_root;
+ 			$cache_dir .= '/' . substr( $hash, 0, 5 ) . '/' . substr( $hash, 5, 5 );
+         remove_directory( $cache_dir );
+	   	break;
+		case 'cat':
+	      $name = CategoryURL( $title );
+			$hash = sha1($name);
+   		$cache_dir = (substr($this->cache_root,-1) == '/') ? substr( $this->cache_root, 0, -1 ) : $this->cache_root;
+   		$cache_dir .= '/' . substr( $hash, 0, 5 ) . '/' . substr( $hash, 5, 5 );
+         remove_directory( $cache_dir );
+		case 'home':
+	      $name = $GLOBALS['cSite']['sSiteRoot'];
+			$hash = sha1($name);
+   		$cache_dir = (substr($this->cache_root,-1) == '/') ? substr( $this->cache_root, 0, -1 ) : $this->cache_root;
+   		$cache_dir .= '/' . substr( $hash, 0, 5 ) . '/' . substr( $hash, 5, 5 );
+         remove_directory( $cache_dir );
+		   break;
+		case 'page':
+         $name = $GLOBALS['cSite']['sSiteRoot'] . 'docs/' . $id;
+			$hash = sha1($name);
+   		$cache_dir = (substr($this->cache_root,-1) == '/') ? substr( $this->cache_root, 0, -1 ) : $this->cache_root;
+   		$cache_dir .= '/' . substr( $hash, 0, 5 ) . '/' . substr( $hash, 5, 5 );
+         remove_directory( $cache_dir );
+			break;
+	   default:
+	   	break;
+	}
+}
+
+
+//-----------------------------------------------------------------------------------------
+function clear_cache()
+{
+	// empty the cache dir
+	remove_directory( $this->cache_root, TRUE );
+}
+
+
+}//class
+
+
+?>
\ No newline at end of file
Index: C:/web/home/arcade.com/www/docs/doc.php
===================================================================
--- C:/web/home/arcade.com/www/docs/doc.php	(revision 82)
+++ C:/web/home/arcade.com/www/docs/doc.php	(revision 91)
@@ -1,17 +1,18 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.1
+/ ProArcadeScript version: 1.4
 / File description:
 / process html file from this folder and generate a page based on it
 /
-/  2007, ProArcadeScript. All rights reserved.
+/  2007-2009, ProArcadeScript. All rights reserved.
 /*******************************************************************/
-require_once( "../include/config.php" );
-require_once( "../templates/".$cSite["sTemplate"]."/config.php" );
-require_once( "../include/class.FastTemplate.php" );
-require_once( "../include/class.Database.php" );
-require_once( "../include/helpers.php" );
-require_once( "../include/class.Log.php" );
+require( "../include/config.php" );
+require( "../templates/".$cSite["sTemplate"]."/config.php" );
+require( "../include/class.FastTemplate.php" );
+require( "../include/class.Database.php" );
+require( "../include/helpers.php" );
+require( "../include/class.Log.php" );
+require( "../include/class.Cache.php" );

 session_start();

@@ -30,6 +31,15 @@
 $log->clear_log();
 $log->write_event( "doc" );

+// Try to get our page from cache
+$cache = new CCache();
+if( $data = $cache->get() )
+{
+	echo $data;
+	exit();
+}
+
+
 // Integrated (permanent) blocks
 $tpl->define( "tplBHead", "block_head.html" );
 $tpl->define( "tplMain", "page_custom.html" );
@@ -82,5 +92,7 @@
 //	parse and make the page visible
 $tpl->parse( "HEAD", "tplBHead" );
 $tpl->parse( "MAIN", "tplMain" );
+$data = $tpl->GetText('MAIN');
+$cache->write( $data );
 $tpl->FastPrint( "MAIN");
 ?>
\ No newline at end of file
Index: C:/web/home/arcade.com/www/admin/pages.php
===================================================================
--- C:/web/home/arcade.com/www/admin/pages.php	(revision 82)
+++ C:/web/home/arcade.com/www/admin/pages.php	(revision 91)
@@ -10,11 +10,14 @@
 require_once( "../include/helpers.php" );
 require_once( "../include/class.FastTemplate.php" );
 require_once( "../include/class.Database.php" );
+require( "../include/class.Cache.php" );

 $tpl = new FastTemplate("templates");

 require( "checklogin.php" );

+$cache = new CCache();
+
 //-----------------------------------------------------------------------------
 // Helper function which write the updated config data to the file
 // $deleteID - ID of the record to delete;
@@ -236,6 +239,10 @@
 				"comments"		=>	$_POST['comments']
 			);
 			WriteNewConfig( $cP, 0, 0, $pageRec );
+
+			// clear page's cache
+			$cache->delete( 'page', $id, 0 );
+
 			header( "Location:pages.php" );
 		}
 		break;
Index: C:/web/home/arcade.com/www/admin/settings.php
===================================================================
--- C:/web/home/arcade.com/www/admin/settings.php	(revision 82)
+++ C:/web/home/arcade.com/www/admin/settings.php	(revision 91)
@@ -1,6 +1,6 @@
 <?php
 /********************************************************************************
-/ ProArcadeScript version: 1.1
+/ ProArcadeScript version: 1.4
 / File description:
 / admin panel: site settings
 / IN: "action" - the action admin wants to run
@@ -9,6 +9,7 @@
 /********************************************************************************/
 require_once( "../include/config.php" );
 require_once( "../include/class.FastTemplate.php" );
+require( "../include/class.Cache.php" );

 $tpl = new FastTemplate("templates");

@@ -25,14 +26,15 @@
 	"SITEROOT"			=> $cSite["sSiteRoot"],
 	"TITLE"				=> $cSite["sSiteTitle"] . " Administration - Site Settings",
 	"ATSETTINGS"		=> "Active",
-	"BASEPATHERROR"		=> "",
+	"BASEPATHERROR"	=> "",
 	"URLERROR"			=> "",
-	"TEMPLATEERROR"		=> "",
+	"TEMPLATEERROR"	=> "",
 	"SITETITLEERROR"	=> "",
 	"ADMINEMAILERROR"	=> "",
 	"EMAILERROR"		=> "",
 	"ADMINERROR"		=> "",
-	"PASSWORDERROR"		=> ""
+	'CACHETTLERROR'   => '',
+	"PASSWORDERROR"	=> ""
 ));


@@ -49,6 +51,7 @@
 		if( empty($_POST["admin"]) )		{	$bEverythingOk = false;	$tpl->assign( "ADMIN", $cLang["errAEmpty"] );	}
 		if( empty($_POST["admin_email"]) )	{	$bEverythingOk = false;	$tpl->assign( "ADMINEMAILERROR", $cLang["errAEmpty"] );	}
 		if( empty($_POST["contact_email"]) ){	$bEverythingOk = false;	$tpl->assign( "EMAILERROR", $cLang["errAEmpty"] );	}
+		if( empty($_POST["cache_ttl"]) ){	$bEverythingOk = false;	$tpl->assign( "CACHETTLERROR", $cLang["errAEmpty"] );	}
 		if( $_POST["password"] != $_POST["password_copy"] ){	$bEverythingOk = false;	$tpl->assign( "PASSWORDERROR", $cLang["errAPassword"] );	}
 	}
 	//
@@ -69,13 +72,20 @@
 				"ADMIN"			=>	$_POST["admin"],
 				"ADMINEMAIL"	=>	$_POST["admin_email"],
 				"CONTACTEMAIL"	=>	$_POST["contact_email"],
+				"CACHETTL"     => $_POST['cache_ttl'],
 				"MAILSIGNATURE"	=>	get_magic_quotes_gpc() ? $_POST["signature"] : mysql_escape_string($_POST["signature"])
 			));
+
 			if( $cSite["bSeo"] )
 				$tplConfig->assign( "SEO", "true" );
 			else
 				$tplConfig->assign( "SEO", "false" );
-		}
+
+			if( $cSite["bCache"] )
+				$tplConfig->assign( "CACHE", "true" );
+			else
+			   $tplConfig->assign( "CACHE", "false" );
+		} // action = Submit
 		else
 		{
 			$tplConfig->assign( array(
@@ -89,13 +99,32 @@
 				"ADMIN"			=> $cSite["sAdminName"],
 				"ADMINEMAIL"	=> $cSite["sAdminEmail"],
 				"CONTACTEMAIL"	=> $cSite["sContactEmail"],
+				'SEO'          => $cSite['bSeo'] ? 'true' : 'false',
+				'CACHE'        => $cSite['bCache'] ? 'true' : 'false',
+				'CACHETTL'     => $cSite['cacheTTL'],
 				"MAILSIGNATURE"	=> get_magic_quotes_gpc() ? $cSite["MailSignature"] : mysql_escape_string($cSite["MailSignature"])
 			));
+
 			if( $_REQUEST["action"] == "disable_seo" )
+			{
 				$tplConfig->assign( "SEO", "false" );
+				$cache = new CCache();
+				$cache->clear_cache();
+			}
 			else if( $_REQUEST["action"] == "enable_seo" )
+			{
 				$tplConfig->assign( "SEO", "true" );
+				$cache = new CCache();
+				$cache->clear_cache();
+			}
+
+			if( $_REQUEST["action"] == "disable_cache" )
+				$tplConfig->assign( "CACHE", "false" );
+			else if( $_REQUEST["action"] == "enable_cache" )
+				$tplConfig->assign( "CACHE", "true" );
+
 		}
+
 		if( !empty($_POST["password"]) )
 			$tplConfig->assign( "ADMINPASSWORD", md5($_POST["password"]) );
 		else
@@ -121,12 +150,19 @@
 			"ADMIN"			=>	$_POST["admin"],
 			"ADMINEMAIL"	=>	$_POST["admin_email"],
 			"CONTACTEMAIL"	=>	$_POST["contact_email"],
+			"CACHETTL"     => $_POST['cache_ttl'],
 			"MAILSIGNATURE"	=>	$_POST["signature"]
 		));
+
 		if( $cSite["bSeo"] == 0 )
 			$tpl->assign( "SEOBUTTON", "<a class=\"Btn Off\" href=\"settings.php?action=enable_seo\"><b>Disabled</b>, click to enable</a>" );
 		else
 			$tpl->assign( "SEOBUTTON", "<a class=\"Btn On\" href=\"settings.php?action=disable_seo\"><b>Enabled</b>, click to disable</a>" );
+
+		if( $cSite['bCache'] == 0 )
+			$tpl->assign( "CACHEBUTTON", "<a class=\"Btn Off\" href=\"settings.php?action=enable_cache\"><b>Disabled</b></a>" );
+		else
+			$tpl->assign( "CACHEBUTTON", "<a class=\"Btn On\" href=\"settings.php?action=disable_cache\"><b>Enabled</b></a>" );
 	}
 }
 else	//if submit is not set
@@ -143,12 +179,19 @@
 		"ADMIN"			=> $cSite["sAdminName"],
 		"ADMINEMAIL"	=> $cSite["sAdminEmail"],
 		"CONTACTEMAIL"	=> $cSite["sContactEmail"],
+		'CACHETTL'     => $cSite['cacheTTL'],
 		"MAILSIGNATURE"	=> $cSite["MailSignature"]
 	));
+
 	if( $cSite["bSeo"] == 0 )
 		$tpl->assign( "SEOBUTTON", "<a class=\"Btn Off\" href=\"settings.php?action=enable_seo\"><b>Disabled</b>, click to enable</a>" );
 	else
 		$tpl->assign( "SEOBUTTON", "<a class=\"Btn On\" href=\"settings.php?action=disable_seo\"><b>Enabled</b>, click to disable</a>" );
+
+	if( $cSite['bCache'] == 0 )
+		$tpl->assign( "CACHEBUTTON", "<a class=\"Btn Off\" href=\"settings.php?action=enable_cache\"><b>Disabled</b></a>" );
+	else
+		$tpl->assign( "CACHEBUTTON", "<a class=\"Btn On\" href=\"settings.php?action=disable_cache\"><b>Enabled</b></a>" );
 }

 $tpl->parse( "ADMINHEADER", "tplHeader" );
Index: C:/web/home/arcade.com/www/admin/install.php
===================================================================
--- C:/web/home/arcade.com/www/admin/install.php	(revision 82)
+++ C:/web/home/arcade.com/www/admin/install.php	(revision 91)
@@ -1,10 +1,10 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.1
+/ ProArcadeScript version: 1.4
 / File description:
 / utility - game pack installator. Moves the given sql to the database
 /
-/  2007, ProArcadeScript. All rights reserved.
+/  2007-2009, ProArcadeScript. All rights reserved.
 /*******************************************************************/
 require_once( "../include/config.php" );
 require_once( "../include/helpers.php" );
@@ -200,7 +200,8 @@
 			foreach( $rescat as $category )
 			{
 				$res = $db->super_query( "SELECT category_id, COUNT(category_id) as count FROM ".$cMain["dbPrefix"]."games WHERE category_id=".$category["id"]." GROUP BY category_id" );
-				$db->query( "UPDATE ".$cMain["dbPrefix"]."categories SET games=".$res["count"]." WHERE id=".$res["category_id"] );
+				$gamescount = empty($res) ? 0 : $res["count"];
+				$db->query( "UPDATE ".$cMain["dbPrefix"]."categories SET games=".$gamescount." WHERE id=".$category["id"] );
 			}
 			$tpl->assign( "MESSAGE", "<b>Done. $ninstalled games have been installed.</b>" );
 			$tpl->assign( "CODE", "" );
Index: C:/web/home/arcade.com/www/admin/index.php
===================================================================
--- C:/web/home/arcade.com/www/admin/index.php	(revision 82)
+++ C:/web/home/arcade.com/www/admin/index.php	(revision 91)
@@ -7,15 +7,29 @@
 /
 /  2007, ProArcadeScript. All rights reserved.
 /********************************************************************************/
-require_once( "../include/config.php" );
-require_once( "../include/helpers.php" );
-require_once( "../include/class.FastTemplate.php" );
-require_once( "../include/class.Database.php" );
+require( "../include/config.php" );
+require( "../include/helpers.php" );
+require( "../include/class.FastTemplate.php" );
+require( "../include/class.Database.php" );
+require( "../include/class.Cache.php" );

 $tpl = new FastTemplate("templates");

 include( "checklogin.php" );

+if( isset($_REQUEST['action']) )
+{
+	// Clear cache
+	if( $_REQUEST['action'] == 'clear_cache' )
+	{
+	   $cache = new CCache();
+		$cache->clear_cache();
+  		header( 'Location:' . $_SERVER['HTTP_REFERER'] );
+		exit();
+	}
+}
+
+// Show the page
 $tpl->define( "tplHeader", "header.html" );
 $tpl->define( "tplFooter", "footer.html" );
 $tpl->define( "tplMain", "page_home.html" );
@@ -26,6 +40,7 @@
 	"ATHOME"	=>	"Active",
 	"SCRIPTVERSION"	=> $version
 ));
+

 $db = new CDatabase( $cMain["dbUser"], $cMain["dbPassword"], $cMain["dbName"], $cMain["dbHost"], 0 );
Index: C:/web/home/arcade.com/www/admin/templates/sitesettings.tpl
===================================================================
--- C:/web/home/arcade.com/www/admin/templates/sitesettings.tpl	(revision 82)
+++ C:/web/home/arcade.com/www/admin/templates/sitesettings.tpl	(revision 91)
@@ -1,10 +1,10 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.1
+/ ProArcadeScript version: 1.4
 / File description:
 / Site configuration. Edit it manually or using admin's control panel
 /
-/  2007, ProArcadeScript. All rights reserved.
+/  2007-2009, ProArcadeScript. All rights reserved.
 /*******************************************************************/

 $cSite = array(
@@ -18,7 +18,9 @@
 	"sSiteKeywords"	=>	"!KEYWORDS!",
 	"sTemplate"		=>	"!TEMPLATE!",
 	"bSeo"			=>	!SEO!,		// search engine friendly links
-
+	"bCache"       => !CACHE!,
+	"cacheTTL"     => !CACHETTL!,
+
 //  Site Admin information
 	"sAdminName"		=>	"!ADMIN!",
 	"sAdminEmail"		=>	"!ADMINEMAIL!",
Index: C:/web/home/arcade.com/www/admin/templates/page_home.html
===================================================================
--- C:/web/home/arcade.com/www/admin/templates/page_home.html	(revision 82)
+++ C:/web/home/arcade.com/www/admin/templates/page_home.html	(revision 91)
@@ -33,6 +33,7 @@
 <ul class="Submenu" style="text-align:left; padding-left:0; margin-left:0;">
 	<li><a href="install.php">Install gamepack</a></li>
 	<li><a href="stats.php">Show Statistics</a></li>
+	<li><a href="index.php?action=clear_cache">Clear Cache</a></li>
 </ul>

 <h3>Other Info</h3>
Index: C:/web/home/arcade.com/www/admin/templates/page_settings.html
===================================================================
--- C:/web/home/arcade.com/www/admin/templates/page_settings.html	(revision 82)
+++ C:/web/home/arcade.com/www/admin/templates/page_settings.html	(revision 91)
@@ -35,11 +35,30 @@
 		<div class="Input"><input class="Med Text" type="Text" name="copyright" value="!COPYRIGHT!" /></div>
 	</div>
 	<div class="Block">
-		<div class="Title">SEO-friendly URLs</div>
+		<div class="Title">SEO-friendly URLs are</div>
 		<div class="Input">!SEOBUTTON!</div>
 	</div>
+	<div class="Small left">Please note, switching SEO URLs will force system to clean up the cache</div>
 </div>

+<h3>Cache Settings</h3>
+<div class="Left" style="width:70%;">
+  	<div class="Block" style="padding-right:15px;">
+		<div class="Title">Cache is</div>
+		<div class="Input">!CACHEBUTTON!</div>
+	</div>
+  	<div class="Block" style="padding-right:15px;">
+		<div class="Title">Time to leave</div>
+		<div class="Input"><input class="Short Text" type="Text" name="cache_ttl" value="!CACHETTL!" /> seconds <span class="Error">!CACHETTLERROR!</span></div>
+	</div>
+  	<div class="Block" style="padding-right:15px;">
+		<div class="Title">&nbsp;</div>
+		<div class="Input left"><a class="Btn Off" href="index.php?action=clear_cache">Clear Cache</a></div>
+	</div>
+</div>
+
+
+
 <h3>Administration &amp; Contact </h3>
 <div class="Left">
 	<div class="Block">
Index: C:/web/home/arcade.com/www/admin/import.php
===================================================================
--- C:/web/home/arcade.com/www/admin/import.php	(revision 0)
+++ C:/web/home/arcade.com/www/admin/import.php	(revision 91)
@@ -0,0 +1,151 @@
+<?php
+/*******************************************************************
+/ ProArcadeScript version: 1.3.3
+/ File description:
+/ Import games data from other databases
+/
+/  20007-2008, ProArcadeScript. All rights reserved.
+/*******************************************************************/
+require_once( "../include/config.php" );
+require_once( "../include/helpers.php" );
+require_once( "../include/class.FastTemplate.php" );
+require_once( "../include/class.Database.php" );
+
+$tpl = new FastTemplate( "templates" );
+
+include( "checklogin.php" );
+
+// Connect to the database
+$db = new CDatabase( $cMain["dbUser"], $cMain["dbPassword"], $cMain["dbName"], $cMain["dbHost"], 0 );
+
+$tpl->define( array(
+	"tplHeader"	=> "header.html",
+	"tplFooter"	=> "footer.html",
+	"tplMain"	=> "page_install.html"
+));
+
+if( isset($_POST["nextstep"]) )
+{
+	$tpl->define( "tplMain", "import".$_POST["nextstep"].".html" );
+	if( isset($_POST["games"]) ) $tpl->assign( "GAMES", $_POST["games"] );
+	if( isset($_POST["categories"]) ) $tpl->assign( "CATEGORIES", $_POST["categories"] );
+	if( isset($_POST["cat_id"]) ) $tpl->assign( "CATID", $_POST["cat_id"] );
+	if( isset($_POST["cat_title"]) ) $tpl->assign( "CATTITLE", $_POST["cat_title"] );
+	if( isset($_POST["cat_size"]) ) $tpl->assign( "CATSIZE", $_POST["cat_size"] );
+	switch( $_POST["nextstep"] )
+	{
+		case 2:
+			// fill up the list of source categories
+			$str = "";
+			$result = $db->query( "SELECT * FROM " . $_POST["categories"], true );
+			$fields = $db->get_result_fields( $result );
+			foreach( $fields as $i => $value )
+				$str .= "<option value=\"".$value->name."\">".$value->name."</option>";
+			$tpl->assign( "FIELDLIST", $str );
+			break;
+		case 3:
+			// List source table
+			$result = $db->super_query( "SELECT * FROM " . $_POST["categories"], true );
+			$str = "";
+			foreach( $result as $i => $values )
+			{
+				$strsize = (!empty($_POST["cat_size"]) ) ? " (" . $values[$_POST["cat_size"]] . ")" : "";
+				$str .= "<p>".$values[$_POST["cat_title"]] . $strsize . " <input name=\"srccat" .
+				$values[$_POST["cat_id"]] . "\"  type=\"text\" size=\"3\"></p>" .
+				"<input name=\"cattitle" . $values[$_POST["cat_id"]] . "\" type=\"hidden\" value=\"" .
+				$values[$_POST["cat_title"]] . "\">\n";
+			}
+			$tpl->assign( "SOURCECATEGORYLIST", $str );
+			// List destination table
+			$result = $db->super_query( "SELECT title, id FROM " . $cS["dbPrefix"] . "categories", true );
+			$str = "";
+			foreach( $result as $i => $values )
+				$str .= "<p>".$values["title"].", ID = ".$values["id"]."</p>";
+			$tpl->assign( "DESTCATEGORYLIST", $str );
+			break;
+		case 4:
+			// Create new categories in our cat. table using data from the previous step
+			$str = "";
+			foreach( $_POST as $var => $value )
+			{
+				if( strstr($var, "srccat") )
+				{
+					$nSrcCat = (int)str_replace("srccat", "", $var);
+					$sCatTitle = $_POST["cattitle".$nSrcCat];
+					if( !empty($value) )
+					{
+						// if this is a new category to our table, add it!
+						if( count($db->super_query( "SELECT id FROM " . $cS["dbPrefix"] . "categories WHERE id=\"$value\"", true)) == 0)
+							$db->query( "INSERT INTO " . $cS["dbPrefix"] . "categories (id, title) VALUES (\"$value\", \"$sCatTitle\")", true );
+						// and anyway store the info about the categories in hidden fields
+						$str .= "<input name=\"" . $var . "\" type=\"hidden\" value=\"" . $value . "\">\n";
+					}
+				}
+			}
+			$tpl->assign( "CATEGORYIDS", $str );
+
+			// Show the list of fields in the "games" table to choose the "ID", "Title", etc. like we did for categories
+			$result = $db->super_query( "SELECT * FROM " . $_POST["games"], true );
+
+			// fill up the list of source categories
+			$str = "";
+			$result = $db->query( "SELECT * FROM " . $_POST["games"], true );
+			$fields = $db->get_result_fields( $result );
+			foreach( $fields as $i => $value )
+				$str .= "<option value=\"".$value->name."\">".$value->name."</option>";
+			$tpl->assign( "FIELDLIST", $str );
+			break;
+		case 5:
+			// create an array of category ID associations: arCatID [oldID] = newID
+			$arIndex = Array();
+			foreach( $_POST as $var => $value )
+				if( strstr($var, "srccat") )
+				{
+					$nSrcCat = (int)str_replace("srccat", "", $var);
+					$arIndex[$nSrcCat] = $value;
+				}
+
+			// Now copy games from the donor table to our one
+			$src = $db->super_query( "SELECT * FROM " . $_POST["games"], true );
+			foreach( $src as $i => $game )
+			{
+				$query = "INSERT INTO " . $cS["dbPrefix"] . "games (category_id, added, active, title, file, thumbnail, width, height";
+				if( !empty($_POST["game_keywords"]) ) $query .= ", keywords";
+				if( !empty($_POST["game_description"]) ) $query .= ", description";
+				if( !empty($_POST["game_plays"]) ) $query .= ", plays_total";
+				if( !empty($_POST["game_playstoday"]) ) $query .= ", plays_today";
+				$catID = $arIndex[$game[$_POST["game_catid"]]];
+
+				// proceed only if we do import the category which the current game belongs
+				if( !empty($catID) )
+				{
+					$date = Today();
+					$title = addslashes( $game[$_POST["game_title"]] );
+					$file = $game[$_POST["game_file"]];
+					$thumb = $game[$_POST["game_thumb"]];
+					$width = $game[$_POST["game_width"]];
+					$height = $game[$_POST["game_height"]];
+					$query .= ") VALUES ('$catID', '$date', 1, '$title', '$file', '$thumb', '$width', '$height'";
+					if( !empty($_POST["game_keywords"]) ) $query .= ", '" . addslashes( $game[$_POST["game_keywords"]] ) . "'";
+					if( !empty($_POST["game_description"]) ) $query .= ", '" . addslashes( $game[$_POST["game_description"]] ) . "'";
+					if( !empty($_POST["game_plays"]) ) $query .= ", '" . $game[$_POST["game_plays"]] . "'";
+					if( !empty($_POST["game_playstoday"]) ) $query .= ", '" . $game[$_POST["game_playstaday"]] . "'";
+					$query .= ")";
+					$db->query( $query, true );
+					echo( $title . "<br>" );
+					flush();
+				}
+			}
+			break;
+		default:
+			header( "Location:import.php" );
+
+	}
+}
+else
+	$tpl->define( "tplMain", "import1.html" );
+
+$tpl->assign( "ACTION", $_SERVER['PHP_SELF'] );
+$tpl->parse( "MAIN", "tplMain" );
+$tpl->FastPrint( "MAIN");
+?>
\ No newline at end of file
Index: C:/web/home/arcade.com/www/admin/content.php
===================================================================
--- C:/web/home/arcade.com/www/admin/content.php	(revision 82)
+++ C:/web/home/arcade.com/www/admin/content.php	(revision 91)
@@ -10,6 +10,7 @@
 require_once( "../include/helpers.php" );
 require_once( "../include/class.FastTemplate.php" );
 require_once( "../include/class.Database.php" );
+require( "../include/class.Cache.php" );

 // few local constants
 $cGamesOnPage = 16;
@@ -19,6 +20,7 @@
 require( "checklogin.php" );

 $db = new CDatabase( $cMain["dbUser"], $cMain["dbPassword"], $cMain["dbName"], $cMain["dbHost"], 0 );
+$cache = new CCache();

 $tpl->define( array(
 	"tplHeader"	=> "header.html",
@@ -43,13 +45,17 @@
 // Utility: Revise games number for each category
 //-----------------------------------------------------------------------------
 	case "revisecategories":
-		$rescat = $db->super_query( "SELECT id FROM ".$cMain["dbPrefix"]."categories", true );
+		$rescat = $db->super_query( "SELECT * FROM ".$cMain["dbPrefix"]."categories", true );
 		foreach( $rescat as $category )
 		{
 			$res = $db->super_query( "SELECT category_id, COUNT(category_id) as count FROM ".$cMain["dbPrefix"]."games WHERE category_id=".$category["id"]." GROUP BY category_id" );
-			$db->query( "UPDATE ".$cMain["dbPrefix"]."categories SET games=".$res["count"]." WHERE id=".$res["category_id"] );
-			header( "Location:" . $_SERVER['HTTP_REFERER'] );
+		   if( $res["category_id"] )
+		   {
+				$query = "UPDATE ".$cMain["dbPrefix"]."categories SET games=".$res["count"]." WHERE id=".$res["category_id"];
+				$db->query( $query );
+			}
 		}
+   	header( "Location:" . $_SERVER['HTTP_REFERER'] );
 		break;

 //-----------------------------------------------------------------------------
@@ -97,6 +103,19 @@
 			// move games to one of the remaining categories
 			$query = "UPDATE " . $cMain["dbPrefix"] . "games SET category_id=" . $_POST["moveto"] . " WHERE category_id=" . $_POST["cat_to_delete"];
 			$db->query( $query );
+
+			// clear cache for each of those games
+			$res = $db->super_query( "SELECT id, latin_title, category_id FROM ".$cMain["dbPrefix"]."games WHERE category_id=" . $_POST["cat_to_delete"], true );
+         foreach( $res as $game_rec )
+            $cache->delete( 'game', $game_rec['id'], $game_rec['latin_title'] );
+
+			// clear category's page cache
+         $res = $db->super_query( "SELECT id, latin_title FROM ".$cMain["dbPrefix"]."categories WHERE id=".$_POST["cat_to_delete"]." LIMIT 1", false );
+ 			$cache->delete( 'cat', 0, $res['latin_title'] );
+
+ 			// clear homepage cache
+ 			$cache->delete( 'home', 0, 0 );
+
 			$query = "DELETE FROM ".$cMain["dbPrefix"]."categories WHERE id=" . $_POST["cat_to_delete"] . " LIMIT 1";
 			$db->query( $query );
 			header ("Location:content.php");
@@ -169,6 +188,9 @@
 				$query .= ', latin_title="'. $_POST['latintitle'].'"';
 			$query .= ', show_on_main="'.$nOnMain.'", description="'.$sDescr.'", keywords="'.$sKeywords.'" WHERE id=' . $_POST["cat"] . ' LIMIT 1';
 			$db->query( $query );
+
+         $res = $db->super_query( "SELECT id, latin_title FROM ".$cMain["dbPrefix"]."categories WHERE id=".$_POST["cat"]." LIMIT 1", false );
+ 			$cache->delete( 'cat', 0, $res['latin_title'] );
 			header ("Location:content.php");
 		}
 		break;
@@ -234,6 +256,10 @@
 					. $sTitle . '", "'. $latintitle . '", "' . $nOnMain . '", "' . $sDescr . '", "'
 					. $sKeywords . '", ' . $position .')';
 				$db->query( $query );
+
+		 		// clear homepage cache
+ 				$cache->delete( 'home', 0, 0 );
+
 				header ("Location:content.php");
 			}
 		}
@@ -390,7 +416,15 @@
 				$db->query( $query );
 				// update number of games in the categories table
 				$db->query( "UPDATE " . $cMain["dbPrefix"] . "categories SET games=games+1 WHERE id=" . $_POST["cat"] . " LIMIT 1" );
-				header ("Location:content.php?action=addgame&result=ok");
+
+				// clear category's page cache
+   	      $res = $db->super_query( "SELECT id, latin_title FROM ".$cMain["dbPrefix"]."categories WHERE id=".$_POST["cat"]." LIMIT 1", false );
+ 				$cache->delete( 'cat', 0, $res['latin_title'] );
+
+			 	// clear homepage cache
+ 				$cache->delete( 'home', 0, 0 );
+
+				header ("Location:content.php?action=addgame&result=ok");
 			}
 		} // action=doaddgame
 		break;
@@ -579,6 +613,7 @@
 			));
 			$tpl->parse( "CATLIST", ".dynCatList" );
 		}
+
 		// process the form data
 		if( $_REQUEST["action"] == "doeditgame" )
 		{
@@ -610,6 +645,10 @@
 					$query .= ', height=' . $_POST['height'];
 				$query .= '  WHERE id=' . $_POST['id'] . ' LIMIT 1';
 				$db->query( $query );
+
+            $res = $db->super_query( "SELECT * FROM ".$cMain["dbPrefix"]."games WHERE id=".$_POST["id"]." LIMIT 1", false );
+    			$cache->delete( 'game', $_POST['id'], $res['latin_title'] );
+
 				header( "Location:".$_POST["referrer"] );
 			}
 		}
@@ -658,6 +697,9 @@
 					unlink( '../content/screenshots/'.$res['large_img'] );
 			// update database
 			$db->query( "DELETE FROM ".$cMain["dbPrefix"]."games WHERE id=".$_REQUEST["id"]." LIMIT 1" );
+			// and delete cache for this game
+			$cache->delete( 'game', $res['id'], $res['latin_title'] );
+
 		}
 		header( "Location:".$_POST["referrer"] );
 		break;
Index: C:/web/home/arcade.com/www/admin/news.php
===================================================================
--- C:/web/home/arcade.com/www/admin/news.php	(revision 82)
+++ C:/web/home/arcade.com/www/admin/news.php	(revision 91)
@@ -5,16 +5,18 @@
 /
 /  2007, ProArcadeScript. All rights reserved.
 /*******************************************************************/
-require_once( "../include/config.php" );
-require_once( "../include/helpers.php" );
-require_once( "../include/class.FastTemplate.php" );
-require_once( "../include/class.Database.php" );
+require( "../include/config.php" );
+require( "../include/helpers.php" );
+require( "../include/class.FastTemplate.php" );
+require( "../include/class.Database.php" );
+require( "../include/class.Cache.php" );

 $tpl = new FastTemplate("templates");

 require( "checklogin.php" );

 $db = new CDatabase( $cMain["dbUser"], $cMain["dbPassword"], $cMain["dbName"], $cMain["dbHost"], 0 );
+$cache = new CCache();

 $tpl->define( array(
 	"tplHeader"	=> "header.html",
@@ -45,11 +47,16 @@
 			"NEWSTITLE"		=>	$sTitle,
 			"NEWSSUMMARY"	=>	$sSummary,
 			"NEWSTEXT"		=>	$sText,
+			"FORMTITLE"		=>	"Add News",
 			"ACTIVECHECKED"	=>	($active) ? "Checked" : ""
 		));
 		if( !empty($_POST["text"]) && !empty($_POST["title"]) )
 		{
 			$db->query( "INSERT INTO ".$cMain["dbPrefix"]."news (title, summary, text, date, active) VALUES ('$sTitle', '$sSummary', '$sText', ".time().", $active)" );
+
+			// clear home page cache to show the news there
+			$cache->delete( 'home', 0, 0 );
+
 			header( "Location:" . $_SERVER['HTTP_REFERER'] );
 		}
 		else
@@ -61,6 +68,8 @@
 //-----------------------------------------------------------------------------
 	case "switchstate":
 		$db->query( "UPDATE ".$cMain["dbPrefix"]."news SET active=MOD(active+1, 2) WHERE id=".$_REQUEST["id"]." LIMIT 1" );
+		// clear home page cache to show the news there
+		$cache->delete( 'home', 0, 0 );
 		header( "Location:" . $_SERVER['HTTP_REFERER'] );
 		break;

@@ -69,6 +78,8 @@
 //-----------------------------------------------------------------------------
 	case "delete":
 		$db->query( "DELETE FROM ".$cMain["dbPrefix"]."news WHERE id=".$_REQUEST["id"]." LIMIT 1" );
+		// clear home page cache to show the news there
+		$cache->delete( 'home', 0, 0 );
 		header( "Location:" . $_SERVER['HTTP_REFERER'] );
 		break;

@@ -82,6 +93,7 @@
 			"NEWSTEXT"		=>	$_POST["text"],
 			"NEWSSUMMARY"	=>	$_POST["summary"],
 			"NEWSTITLE"		=>	$_POST["title"],
+			"FORMTITLE"		=>	"Edit News",
 			"ACTIVECHECKED"	=>	($_POST["text"] == 1) ? "Checked" : ""
 		));
 		if( !empty($_POST["text"]) && !empty($_POST["title"]) )
@@ -92,6 +104,8 @@
 			$sSummary = get_magic_quotes_gpc() ? $_POST["summary"] : mysql_escape_string($_POST["summary"]);
 			$db->query( "UPDATE ".$cMain["dbPrefix"]."news SET title='". $sTitle .
 			"', summary='$sSummary' ,text='$sText', active=$active WHERE id=".$_POST["id"]." LIMIT 1" );
+			// clear home page cache to show the news there
+			$cache->delete( 'home', 0, 0 );
 			header( "Location: news.php" );
 		}
 		{
Index: C:/web/home/arcade.com/www/index.php
===================================================================
--- C:/web/home/arcade.com/www/index.php	(revision 82)
+++ C:/web/home/arcade.com/www/index.php	(revision 91)
@@ -1,6 +1,6 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.1
+/ ProArcadeScript version: 1.4
 / File description:
 / main page visualisation
 /
@@ -12,6 +12,7 @@
 require_once( "include/class.Database.php" );
 require_once( "include/helpers.php" );
 require_once( "include/class.Log.php" );
+require( "include/class.Cache.php" );

 session_start();

@@ -30,6 +31,15 @@
 $log->clear_log();
 $log->write_event( "index" );

+// Try to get our page from cache
+$cache = new CCache();
+if( $data = $cache->get() )
+{
+	echo $data;
+	exit();
+}
+else
+{
 // Integrated (permanent) blocks
 $tpl->define( "tplBHead", "block_head.html" );
 $tpl->define( "tplMain", "page_index.html" );
@@ -65,5 +75,8 @@
 //	parse and make the page visible
 $tpl->parse( "HEAD", "tplBHead" );
 $tpl->parse( "MAIN", "tplMain" );
+$data = $tpl->GetText('MAIN');
+$cache->write( $data );
 $tpl->FastPrint( "MAIN");
+} // no copy in cache
 ?>
\ No newline at end of file
Index: C:/web/home/arcade.com/www/cat.php
===================================================================
--- C:/web/home/arcade.com/www/cat.php	(revision 82)
+++ C:/web/home/arcade.com/www/cat.php	(revision 91)
@@ -1,6 +1,6 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.3
+/ ProArcadeScript version: 1.4
 / File description:
 / Generate and show main page for the given category (arcades, etc.)
 / IN: id - category ID
@@ -13,6 +13,7 @@
 require_once( "include/class.FastTemplate.php" );
 require_once( "include/class.Database.php" );
 require_once( "include/class.Log.php" );
+require( "include/class.Cache.php" );

 session_start();

@@ -26,6 +27,15 @@
 $log = new CLog( $db );
 $log->write_event( "category" );

+// Try to get our page from cache
+$cache = new CCache();
+if( $data = $cache->get() )
+{
+	echo $data;
+	exit();
+}
+else
+{
 // Integrated (permanent) blocks
 $tpl->define(array(	"tplBHead"	=> "block_head.html" ));

@@ -77,5 +87,8 @@
 //	parse and make the page visible
 $tpl->parse( "HEAD", "tplBHead" );
 $tpl->parse( "MAIN", "tplMain" );
+$data = $tpl->GetText('MAIN');
+$cache->write( $data );
 $tpl->FastPrint( "MAIN");
+} // no copy in cache
 ?>
\ No newline at end of file
Index: C:/web/home/arcade.com/www/game.php
===================================================================
--- C:/web/home/arcade.com/www/game.php	(revision 82)
+++ C:/web/home/arcade.com/www/game.php	(revision 91)
@@ -1,11 +1,11 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.3.3
+/ ProArcadeScript version: 1.4
 / File description:
 / Generate and show html page for the given game
 / IN: id - the game's id
 /
-/  2007, ProArcadeScript. All rights reserved.
+/  2007-2009, ProArcadeScript. All rights reserved.
 /*******************************************************************/
 require_once( "include/config.php" );
 require_once( "templates/".$cSite["sTemplate"]."/config.php" );
@@ -13,6 +13,7 @@
 require_once( "include/class.FastTemplate.php" );
 require_once( "include/class.Database.php" );
 require_once( "include/class.Log.php" );
+require( "include/class.Cache.php" );

 session_start();

@@ -22,40 +23,23 @@
 // Connect to the database
 $db = new CDatabase( $cMain["dbUser"], $cMain["dbPassword"], $cMain["dbName"], $cMain["dbHost"], 0 );
 $log = new CLog( $db );
+$cache = new CCache();

-// Integrated (permanent) blocks
-$tpl->define( array(
-	"tplBHead"	=>	"block_head.html",
-	"tplBError"	=>	"block_errormsg.html"
-	));
-
-$tpl->assign( array(
-	"SITEURL"			=> $cSite["sURL"],
-	"SITEROOT"			=> $cSite["sSiteRoot"],
-	"TITLE"				=> $cSite["sSiteTitle"]
-	));
-
 // Find the game's record in DB
-$sWhere = $cSite['bSeo'] ? 'latin_title = "' . $_REQUEST['game'] . '"' : 'id='.$_REQUEST['id'];
-$query = 'SELECT * FROM ' . $cMain['dbPrefix'] . 'games WHERE '. $sWhere . ' AND active=1 LIMIT 1';
+$gameID = 0;
+$query = 'SELECT * FROM ' . $cMain['dbPrefix'] . 'games WHERE ';
+if( $cSite['bSeo'] )
+	$query .= 'latin_title = "' . $_GET['game'] . '" AND active=1 LIMIT 1';
+else
+	$query .= 'id='.$_GET['id'] . ' AND active=1 LIMIT 1';
 $gameres = $db->super_query( $query, false );
-if( empty($gameres) )
-{
-	$gameID = 0;
-	$tpl->define( "tplMain", "page_custom.html" );
-	$thisPage = "custom";
-	$tpl->assign( "PAGECONTENTS", $cLang["errNoGame"] );
-}
-else
-{
+if( !empty($gameres) )
 	$gameID = $gameres['id'];
-	$tpl->define( "tplMain", "page_game.html" );
-	$tpl->assign( 'CURRENTGAMETITLE',  $gameres['title'] );
-	$tpl->assign( 'ID', $gameID );

-	$thisPage = "game";
-	// update stats, write log
-	$db->query( 'UPDATE LOW_PRIORITY ' . $cMain['dbPrefix'] . 'games SET plays_total=plays_total+1, plays_today=plays_today+1 WHERE id='.$gameID.' LIMIT 1' );
+// if the game is found in the database and is active, update what's should be updated and show the content
+if( $gameID != 0 )
+{
+	$db->query( 'UPDATE LOW_PRIORITY ' . $cMain['dbPrefix'] . 'games SET plays_total=plays_total+1, plays_today=plays_today+1 WHERE id='.$gameID.' AND active=1 LIMIT 1' );
 	if( !empty($_SESSION['user']) )
 	{
 		// Prevent possible fraud clicks (for rating increasing)
@@ -66,9 +50,45 @@
 			$db->query( 'UPDATE LOW_PRIORITY ' . $cMain['dbPrefix']
 			. 'users SET gameplays=gameplays+1, rating=rating+' . $cUser['ptPlay'] . ' WHERE id='.$_SESSION['user'].' LIMIT 1' );
 	}
-	$log->write_event( "game", $gameID );
+	$log->write_event( 'game', $gameID );
+
+	// If this page exists in cache, just show it and exit.
+	if( $data = $cache->get() )
+	{
+		echo( $data );
+		exit();
+	}
+
+
+	//If we are still here (no cache for this game), setup some template vars for future parsing
+	$thisPage = "game";
+	$tpl->define( 'tplMain', 'page_game.html' );
+	$tpl->assign( array(
+		'CURRENTGAMETITLE'	=> $gameres['title'],
+		'ID'						=>	$gameID
+	));
 }
-
+else
+{
+	// if the game is not found, we are showing the "error" page
+	$tpl->define( "tplMain", "page_custom.html" );
+	$thisPage = "custom";
+	$tpl->assign( 'PAGECONTENTS', $cLang['errNoGame'] );
+	$tpl->assign( 'METATITLE', $cSite['sSiteTitle'] . ' - ' . $_GET['game'] );
+}
+
+// permanent blocks and constants (we need them in any case)
+$tpl->define( array(
+	'tplBHead'	=>	'block_head.html',
+	'tplBError'	=>	'block_errormsg.html'
+));
+$tpl->assign( array(
+	'SITEURL'			=> $cSite['sURL'],
+	'SITEROOT'			=> $cSite['sSiteRoot'],
+	'TITLE'				=> $cSite['sSiteTitle'],
+));
+
+
 // Page blocks
 foreach( $cB as $id => $cBlock )
 {
@@ -88,7 +108,7 @@
 		$tpl->assign( $id, "" );
 }

-if( !empty($gameres) )
+if( $gameID != 0 )
 {
 	$ext = substr( strrchr($gameres['file'], '.'), 1);
 	if( $cExt[$ext] )
@@ -112,13 +132,13 @@
 				$nHeight = $arGameInfo[1];
 			}
 		}
-		else
+		else
 		{
 			$nWidth = $cTpl['nMaxGameW'];
 			$nHeight = $cTpl['nMaxGameH'];
-		}
-	}
-
+		}
+	}
+
 	$nWidthFactor = $cTpl['nMaxGameW'] / $nWidth;
 	$nHeightFactor = $cTpl['nMaxGameH'] / $nHeight;
 	$nSizeFactor = min( $nWidthFactor, $nHeightFactor );
@@ -151,5 +171,11 @@
 //	parse and make the page visible
 $tpl->parse( "HEAD", "tplBHead" );
 $tpl->parse( "MAIN", "tplMain" );
+$data = $tpl->GetText('MAIN');
+
+// if game is found and active, write cache
+if( $gameID != 0 )
+	$cache->write( $data );
+
 $tpl->FastPrint( "MAIN");
 ?>
Index: C:/web/home/arcade.com/www/content/screenshots/.htaccess
===================================================================
--- C:/web/home/arcade.com/www/content/screenshots/.htaccess	(revision 0)
+++ C:/web/home/arcade.com/www/content/screenshots/.htaccess	(revision 91)
@@ -0,0 +1 @@
+Options -Indexes
\ No newline at end of file
Index: C:/web/home/arcade.com/www/content/thumbs/.htaccess
===================================================================
--- C:/web/home/arcade.com/www/content/thumbs/.htaccess	(revision 0)
+++ C:/web/home/arcade.com/www/content/thumbs/.htaccess	(revision 91)
@@ -0,0 +1 @@
+Options -Indexes
\ No newline at end of file
Index: C:/web/home/arcade.com/www/content/blocks/block_related.php
===================================================================
--- C:/web/home/arcade.com/www/content/blocks/block_related.php	(revision 82)
+++ C:/web/home/arcade.com/www/content/blocks/block_related.php	(revision 91)
@@ -1,6 +1,6 @@
 <?php
 /*******************************************************************
-/ ProArcadeScript version: 1.3.2
+/ ProArcadeScript version: 1.4
 / File description:
 / Show the games that are favorite to people who plays the current one
 /
@@ -8,7 +8,7 @@
 /*******************************************************************/

 // how old (days) must be the data to be considered as obsolete
-$cRelatedDays = 7;
+$cRelatedDays = 1;

 // proceed only if the game is found
 if( $gameID > 0 )
Index: C:/web/home/arcade.com/www/content/blocks/block_path.php
===================================================================
--- C:/web/home/arcade.com/www/content/blocks/block_path.php	(revision 82)
+++ C:/web/home/arcade.com/www/content/blocks/block_path.php	(revision 91)
@@ -20,12 +20,20 @@
 		$tpl->assign( "CURRENTPATH", $sCategory );
 		break;
 	case "game.php":
-		$query = "SELECT id, title, latin_title FROM " . $cMain["dbPrefix"] . "categories WHERE id=".$gameres['category_id']." LIMIT 1";
-		$res = $db->super_query( $query, false );
-		$tpl->assign( "PATHURL", CategoryURL($res["latin_title"]) );
-		$tpl->assign( "PATHTITLE", $res["title"] );
-		$tpl->parse( "PATH", ".dynPath" );
-		$tpl->assign( "CURRENTPATH", $gameres['title'] );
+	   if( $gameID != 0 )
+	   {
+			$query = "SELECT id, title, latin_title FROM " . $cMain["dbPrefix"] . "categories WHERE id=".$gameres['category_id']." LIMIT 1";
+			$res = $db->super_query( $query, false );
+			$tpl->assign( "PATHURL", CategoryURL($res["latin_title"]) );
+			$tpl->assign( "PATHTITLE", $res["title"] );
+			$tpl->parse( "PATH", ".dynPath" );
+			$tpl->assign( "CURRENTPATH", $gameres['title'] );
+		}
+		else
+		{
+			$tpl->clear_dynamic( "dynPath" );
+		   $tpl->assign( 'CURRENTPATH', $cLang['errUnknown'] );
+		}
 		break;
 	case "userhome.php":
 		$tpl->assign( "CURRENTPATH", $page_path );
Index: C:/web/home/arcade.com/www/content/blocks/.htaccess
===================================================================
--- C:/web/home/arcade.com/www/content/blocks/.htaccess	(revision 0)
+++ C:/web/home/arcade.com/www/content/blocks/.htaccess	(revision 91)
@@ -0,0 +1 @@
+Options -Indexes
\ No newline at end of file
Index: C:/web/home/arcade.com/www/userhome.php
===================================================================
--- C:/web/home/arcade.com/www/userhome.php	(revision 82)
+++ C:/web/home/arcade.com/www/userhome.php	(revision 91)
@@ -183,9 +183,11 @@
 				));
 				$mailtpl->parse( BODY, "tplBody" );
 				$sBody = $mailtpl->GetText( "BODY" );
-				$sTo = $_POST['name'] . '<'.$_POST['email'].'>';
-				$sFrom = $cSite['sSiteTitle'].' <'.$cSite['sContactEmail'].'>';
-				$header = "From: $sFrom\r\n X-Mailer: Content Manager - PHP/" . phpversion();
+				$sTo = $_POST['email'];
+				$sFrom = $cSite['sContactEmail'];
+				$header = "From: $sFrom\r\n" .
+     						 "Reply-To: $sFrom\r\n" .
+     						 "X-Mailer: PHP/" . phpversion();
 				$subj = str_replace( 'SITENAME', $cSite['sSiteTitle'], $cLang['sActivationSubj'] );
 				if( @mail( $sTo, $subj, $sBody, $header ) )
 					$tpl->assign( "MESSAGE", $cLang['msgAccountCreated'] );
